{% extends "base.html" %} {% block content %}
<h2 class="mb-4">最新文章</h2>

{% if posts %} {% for post in posts %}
<div class="card mb-4">
  <div class="card-body">
    <h3 class="card-title">
      <a
        href="{{ url_for('post', post_id=post.id) }}"
        class="text-decoration-none"
        >{{ post.title }}</a
      >
    </h3>
    <p class="card-text text-muted">
      作者:
      <a href="{{ url_for('user_posts', username=post.author.username) }}"
        >{{ post.author.username }}</a
      >
      | 发布时间: {{ post.date_posted.strftime('%Y-%m-%d %H:%M') }}
    </p>
    <p class="card-text">
      {{ post.content[:200] }}{% if post.content|length > 200 %}...{% endif %}
    </p>
    <a href="{{ url_for('post', post_id=post.id) }}" class="btn btn-primary"
      >阅读全文</a
    >
  </div>
</div>
{% endfor %} {% else %}
<div class="alert alert-info">暂无文章，快去发布你的第一篇文章吧！</div>
{% endif %} {% endblock %}
